package com.easepal802s.project.ui.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.clj.fastble.data.BleDevice;
import com.easepal802s.project.utils.ActivityUtils;
import com.ogawa.base.Constant.BleConstant;
import com.easepal802s.project.R;
import com.easepal802s.project.ble.BleController;
import com.easepal802s.project.observer.BleDataObserver;
import com.easepal802s.project.ui.iview.IShoulderAdjustView;
import com.easepal802s.project.ui.presenter.ShoulderAdjustPresenter;
import com.easepal802s.project.view.LongClickImageView2;
import com.ogawa.base.utils.CommonUtil;

import static com.easepal802s.project.ble.BleController.CONNECT_BREAK;


/**
 * 肩部调整
 */
public class ShouldersAdjustmentActivity extends BaseMvpTestActivity<ShoulderAdjustPresenter, ShouldersAdjustmentActivity> implements View.OnClickListener,IShoulderAdjustView, LongClickImageView2.onDownAction,BleDataObserver.OnBleListerner {


    private LongClickImageView2 mIvUp;
    private LongClickImageView2 mIvDown;
    private int count = 1;
    private static  onCloseAdjust mAcation;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shoulders_adjustment);
        BleDataObserver.getInst().registerBleDataObserver(this);
        initView();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        BleDataObserver.getInst().removeBleDataObserver(this);
        mAcation = null;
    }

    @Override
    public ShoulderAdjustPresenter initPresenter() {
        return new ShoulderAdjustPresenter(this);
    }

    @Override
    protected void initCreateView(Bundle savedInstanceState) {

    }

    @Override
    public ShouldersAdjustmentActivity initActivity() {
        return this;
    }


    private void initView() {
        mIvUp =findViewById(R.id.img_shoulder_up);
        mIvDown =findViewById(R.id.img_shoulder_down);
        findViewById(R.id.img_shoulder_ok).setOnClickListener(this);
        mIvUp.setCommondAction(BleConstant.JIXINUP,this);
        mIvUp.intiListener();


        mIvDown.setCommondAction(BleConstant.JIXINDOWM,this);
        mIvDown.intiListener();



    }


    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.img_shoulder_ok:
                if (CommonUtil.isFastClick(350)) {
                    return;
                } else {
                    BleController.getInst().sendSingleData(BleConstant.JIANBQR,true);
                }
                break;
        }

    }
    public static void setAdjustAction(onCloseAdjust action){
        mAcation = action;
    }

    @Override
    public void onConnectState(int state) {

    }

    @Override
    public void onTargetDeviceFind(BleDevice bleDevice) {

    }

    @Override
    public void onStarScan() {

    }

    @Override
    public void onNoDeviceFind() {

    }

    @Override
    public void onGetData(String data) {
        mBasePresenter.getDatas(data);
    }

    @Override
    public void onPowerOff() {
        if(BleController.getInst().getConnectState()==CONNECT_BREAK){
            ActivityUtils.startHomeActivity(this,"BREAK");
        }
        else {
            ActivityUtils.startHomeActivity(this,"none");
        }
        this.finish();

    }

    @Override
    public void onDataChange(String bage, int auto, int skill, int air,String name,String commond) {

    }

    @Override
    public void onShoulderAdjust(int data) {

    }

    @Override
    public void onDownClick(String what) {
        Log.e("LongNext","onDownClick");
        if (CommonUtil.isFastClick()) {
            return;
        } else {
            BleController.getInst().sendLongclickSingleData(what,true);
        }
    }

    public   interface onCloseAdjust{
        void adjustClose();

    }

    @Override
    public void onBackPressed() {
        if(mAcation!=null){
            mAcation.adjustClose();
        }

        this.finish();

    }

    @Override
    public void isFinish() {

        this.finish();
    }



}
